package cn.oms.manage.dao.persist.repository.impl;

import cn.oms.commons.pojo.vo.PageData;
import cn.oms.commons.util.PageInfoToPageDataConverter;
import cn.oms.manage.dao.persist.mapper.RecordMapper;
import cn.oms.manage.dao.persist.repository.IRecordRepository;
import cn.oms.manage.pojo.entity.Medicine;
import cn.oms.manage.pojo.entity.Order;
import cn.oms.manage.pojo.entity.Record;
import cn.oms.manage.pojo.vo.MedicineListVO;
import cn.oms.manage.pojo.vo.MedicineStandardVO;
import cn.oms.manage.pojo.vo.RecordListVO;
import cn.oms.manage.pojo.vo.RecordStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 说明：
 *
 * @author:Hyx
 * @date:2023/6/16
 **/
@Slf4j
@Repository
public class RecordRepositoryImpl implements IRecordRepository {
    @Autowired
    private RecordMapper recordMapper;

    public RecordRepositoryImpl(){
        log.debug("创建数据访问实现类对象:RecordRepositoryImpl");
    }

    @Override
    public int insert(Record record){
        log.debug("开始执行【插入诊断记录】的数据访问，参数：{}",record);
        return recordMapper.insert(record);
    }


    //    @Override
//    public int insertBatch(List<Record> recordList){
//        log.debug("开始执行【批量插入诊断记录】的数据访问，参数：{}",recordList);
//        return recordMapper.insertBatch(recordList);
//    }
    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除诊断记录】的数据访问，参数：{}", id);
        return recordMapper.deleteById(id);
    }

    @Override
    public int update(Record record) {
        log.debug("开始执行【修改相册】的数据访问，参数：{}", record);
        return recordMapper.updateById(record);
    }

    @Override
    public int countByCustomer(Long CustomerId) {
        log.debug("开始执行【统计匹配客户的诊断记录的数量】的数据访问，id：{}", CustomerId);
        QueryWrapper<Record> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", CustomerId);
        return recordMapper.selectCount(queryWrapper);
    }

    @Override
    public int renew(Long id){
        log.debug("开始执行【根据ID刷新诊断记录】的数据访问，参数：{}", id);
        return recordMapper.renew(id);
    }

//    @Override
//    public int countByName(String name) {
//        log.debug("开始执行【统计匹配名称的相册的数量】的数据访问，参数：{}", name);
//        QueryWrapper<Medicine> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("name", name);
//        return recordMapper.selectCount(q);
//    }

    @Override
    public RecordStandardVO getStandardById(Long id) {
        log.debug("开始执行【根据ID查询诊断记录信息】的数据访问，参数：{}", id);
        return recordMapper.getStandardById(id);
    }

    @Override
    public PageData<RecordListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询诊断记录列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<RecordListVO> list = recordMapper.list();
        PageInfo<RecordListVO> pageInfo = new PageInfo<>(list);
        PageData<RecordListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;
    }
    
}
